//commit 3


package com.example.firstgame2;

import java.util.HashMap;

import com.example.firstgame2.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class DrawView extends View {
	private int ypos =10, radius =10,guy=30;
	private int[] xpos =new int[guy];

	private int[] speedx=new int[guy];


	private int speedy =-10;
	private int a=-10;
	private int width , height;	
	private Paint paint;
	double[] t=new double[guy];
	int[] u=new int[guy];
	Bitmap[] android_guy=new Bitmap[guy];


	public DrawView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		setFocusable(true);
		this.requestFocus();
		setBackgroundColor(Color.LTGRAY);


		for (int i=0;i<guy;i++){
			android_guy[i] = 
					BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_launcher);
			xpos[i]=5;
			speedx[i]=i;
			t[i]=0;
			u[i]=80+i;
		}


		paint = new Paint();
		paint.setColor(Color.RED);
	}


	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		// TODO Auto-generated method stub
		super.onSizeChanged(w, h, oldw, oldh);
		width =w;
		height =h;
		ypos=height;
	}



	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		//canvas.drawLine(3, 5, 33, 55, paint); //paint store the color
		//canvas.drawCircle(100, 100, 50, paint);
		//canvas.drawCircle(240, 400, 120, paint);
		//canvas.drawCircle(xpos, ypos, radius, paint);

		for (int i=0;i<guy;i++){
			int s1=(int) (a*t[i]*t[i]/2);
			int s2=(int) (u[i]*t[i]);
			int s=s2+s1;
			xpos[i] +=speedx[i];
			ypos =(int) (height-50-s);

			canvas.drawBitmap(android_guy[i], xpos[i],ypos, paint);



			if((xpos[i]) > width||(xpos[i]) < 0  ) speedx[i] = -speedx[i];
			if((ypos) < 0 ) {}
			if ((ypos) > height) {t[i]=0;}
			t[i]=t[i]+0.1;
		}



		try{
			Thread.sleep(1); //EVERy 30ms sleep
		} catch (InterruptedException e) {}

		invalidate(); //continous call the fuunction


	}



}
